<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
	<title>基础数据-物品管理</title>
	<meta charset="utf-8">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>libs/bootstrap-3.3.7-dist/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/reset.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/style.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/iframe.css">
</head>
<body>
	<div id="mainContent">
		<div id="mainContent_content">
			<div class="page_header"><a>物品管理</a></div>
			<div class="search">
			<form action="<%=basePath %>iteminfo/listItem.do" method="post" class="form">
				<p>
						<label>物品代码</label>
						<input type="text" name="itemcode" value="${iteminfoPage.itemcode }" class="form-control"></input>
						<label>物品名称</label>
						<input type="text" name="itemname" value="${iteminfoPage.itemname }" class="form-control"></input>
						<label>状态</label>
						<select name="status" class="form-control select">
							<option value="">全部</option>
							<option value="0" ${iteminfoPage.status=="0"?"selected":"" }>可用</option>
							<option value="1" ${iteminfoPage.status=="1"?"selected":"" }>不可用</option>
						</select>
						<label>类型</label>
						<select name="materialMaterial" class="form-control select">
							<option value="">全部</option>
							<option value="IMPA物料"
								${iteminfoPage.materialMaterial=="IMPA物料"?"selected":"" }>IMPA物料</option>
							<option value="普通物料" ${iteminfoPage.materialMaterial=="普通物料"?"selected":"" }>普通物料</option>
						</select>
						<input type="submit" value="查询" class="btn btn1"></input>
						<c:if test="${isAdd }">
						<input type="button" value="新增" onclick="toAddGoods();" class="btn btn2"></input>
						</c:if>
						<input type="button" value="编辑" onclick="toEditGoods();" class="btn btn1"></input>
						<c:if test="${isDelete }">
						<input type="button" value="删除" onclick="toDeleteGoods();" class="btn btn_danger"></input>
						</c:if>
				</p>
			</form>
			</div>
			<div class="tableBox box">
				<table class="table table-bordered table_text_center">
					<thead>
						<tr>
							<th></th>
							<th style="width:140px;">操作</th>
							<th>物品编码</th>
							<th>物品名称</th>
							<th>英文名称</th>
							<th>物品条码</th>
							<th>状态</th>
							<th>类型</th>
						</tr>
					</thead>
					<tbody>
						<c:forEach items="${list}" var="iteminfo" varStatus="i">
							<tr onclick="selectRow(this);">
								<td><label class="radio"><input type="radio" name="operateGoods" value="${iteminfo.inteminformationid }"><span class="radio_icon"></span></label></td>
								<td>
								<a class="btn btn-xs btn1" onclick="editGoods(${iteminfo.inteminformationid });">编辑</a>
								<c:if test="${isDelete }">
									<a class="btn btn-xs btn_danger" onclick="confirmDeleteGoods(${iteminfo.inteminformationid });">删除</a>
								</c:if>
								</td>
								<td>${iteminfo.itemcode }</td>
								<td>${iteminfo.chinesename }</td>
								<td>${iteminfo.englishname }</td>
								<td>${iteminfo.articlebarcode }</td>
								<td>
									<c:if test="${iteminfo.itemstatus==0 }">可用</c:if>
									<c:if test="${iteminfo.itemstatus==1 }">不可用</c:if>
								</td>
								<td>${iteminfo.materialmaterial }</td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
			</div>
			<jsp:include page="/jsp/basic/page.jsp"></jsp:include>
		</div>
		<jsp:include page="/jsp/basicData/goodsManage/addGoods.jsp"></jsp:include>
		<jsp:include page="/jsp/basicData/goodsManage/editGoods.jsp"></jsp:include>
		<jsp:include page="/jsp/basic/prompt.jsp"></jsp:include>
	</div>
	<script src="<%=basePath %>js/jquery-3.2.1.min.js"></script>
	<script src="<%=basePath %>libs/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
	<script src="<%=basePath %>js/public.js"></script>
	<script type="text/javascript">

	function selectRow(obj){
		$(obj).find('input:radio[name="operateGoods"]')[0].checked=true;
	}
	
	function toEditGoods(){
		var radio=$('input:radio[name="operateGoods"]:checked');
		if(!radio.val()){
			Prompt.alert("提示","请先选中需要编辑的物品！");
			return;
		}
		editGoods(radio.val());
	}
	
	function toDeleteGoods(){
		var radio=$('input:radio[name="operateGoods"]:checked');
		if(!radio.val()){
			Prompt.alert("删除提示","请先选中需要删除的物品！");
			return;
		}
		confirmDeleteGoods(radio.val());
	}
		
	function confirmDeleteGoods(id){
		var delFunc=function(){
			$.ajax({
				url:"<%=basePath %>iteminfo/delete.do",
				type:"post",
				async : false,
				dataType:"json",
				data : "inteminformationid="+id,
				success:function(data){
					if(data.result=="success"){
						Prompt.alert("删除提示","物品已删除！",Prompt.refresh);
					}
				},
				error :function(){
					Prompt.alert("删除提示","服务器无响应，请刷新页面后重试！");
				}
			});
		}
		Prompt.confirm("提示","确认要删除该物品吗?删除后无法恢复",delFunc);
	}
	</script>
</body>
</html>